class="lines-num lines-num-old"> 238
@@ -1,9 +1,9 @@ |
||
| 1 | 1 |
# -*- coding: utf-8 -*- |
| 2 | 2 |
|
| 3 |
-import logging |
|
| 4 |
-import requests |
|
| 5 | 3 |
import json |
| 4 |
+import logging |
|
| 6 | 5 |
|
| 6 |
+import requests |
|
| 7 | 7 |
from django.conf import settings |
| 8 | 8 |
from django.db import transaction |
| 9 | 9 |
from django_curtail_uuid import CurtailUUID |
@@ -16,14 +16,15 @@ from pywe_storage import RedisStorage |
||
| 16 | 16 |
from TimeConvert import TimeConvert as tc |
| 17 | 17 |
|
| 18 | 18 |
from account.models import UserInfo |
| 19 |
-from mch.models import SaleclerkInfo, DistributorInfo, MaintenancemanInfo |
|
| 20 |
-from statistic.models import RegisterStatisticInfo |
|
| 21 |
-from member.models import RightInfo |
|
| 22 | 19 |
from coupon.models import UserCouponInfo |
| 20 |
+from mch.models import DistributorInfo, MaintenancemanInfo, SaleclerkInfo |
|
| 21 |
+from member.models import RightInfo |
|
| 22 |
+from statistic.models import RegisterStatisticInfo |
|
| 23 | 23 |
from utils.error.errno_utils import ProductBrandStatusCode, ProductDistributorStatusCode, UserStatusCode |
| 24 | 24 |
from utils.redis.connect import r |
| 25 | 25 |
from utils.redis.rprofile import set_profile_info |
| 26 | 26 |
|
| 27 |
+ |
|
| 27 | 28 |
WECHAT = settings.WECHAT |
| 28 | 29 |
logger = logging.getLogger('logit')
|
| 29 | 30 |
|
@@ -48,11 +49,11 @@ def qy_login_api(request): |
||
| 48 | 49 |
|
| 49 | 50 |
token = access_token(appid=appid, secret=secret, storage=RedisStorage(r)) |
| 50 | 51 |
|
| 51 |
- userinfo = requests.post(url='https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token='+token+'&userid='+userid).text |
|
| 52 |
+ userinfo = requests.post(url='https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=' + token + '&userid=' + userid).text |
|
| 52 | 53 |
userinfo = json.loads(userinfo) |
| 53 | 54 |
|
| 54 | 55 |
mobile = userinfo.get('mobile', '')
|
| 55 |
- |
|
| 56 |
+ |
|
| 56 | 57 |
# Get or Create User |
| 57 | 58 |
user, created = UserInfo.objects.select_for_update().get_or_create(appid=appid, userid=userid) |
| 58 | 59 |
|
@@ -83,14 +84,14 @@ def qy_login_api(request): |
||
| 83 | 84 |
if 122 in userinfo.get('department', []):
|
| 84 | 85 |
maintenance, created = MaintenancemanInfo.objects.get_or_create(brand_id=brand_id, maintenance_phone=mobile, status=True) |
| 85 | 86 |
user.is_maintenance = True |
| 86 |
- |
|
| 87 |
+ |
|
| 87 | 88 |
if created: |
| 88 | 89 |
maintenance.maintenance_name = userinfo.get('name', '')
|
| 89 | 90 |
maintenance.maintenance_sex = userinfo.get('gender', 0)
|
| 90 | 91 |
maintenance.maintenance_phone = mobile |
| 91 | 92 |
maintenance.user_id = user.user_id |
| 92 | 93 |
maintenance.wx_userid = userid |
| 93 |
- maintenance.save() |
|
| 94 |
+ maintenance.save() |
|
| 94 | 95 |
else: |
| 95 | 96 |
user.is_maintenance = False |
| 96 | 97 |
# 销售员登录 |
@@ -99,9 +100,9 @@ def qy_login_api(request): |
||
| 99 | 100 |
if created: |
| 100 | 101 |
try: |
| 101 | 102 |
distributor = DistributorInfo.objects.get(department_id__in=userinfo.get('department', []))
|
| 102 |
- except: |
|
| 103 |
+ except DistributorInfo.DoesNotExist: |
|
| 103 | 104 |
return response(ProductDistributorStatusCode.DISTRIBUTOR_NOT_FOUND) |
| 104 |
- |
|
| 105 |
+ |
|
| 105 | 106 |
saleclerk.brand_id = brand_id |
| 106 | 107 |
saleclerk.distributor_id = distributor.distributor_id |
| 107 | 108 |
saleclerk.distributor_name = distributor.distributor_name |
@@ -113,7 +114,7 @@ def qy_login_api(request): |
||
| 113 | 114 |
saleclerk.user_status = SaleclerkInfo.ACTIVATED |
| 114 | 115 |
saleclerk.is_auth = True |
| 115 | 116 |
saleclerk.save() |
| 116 |
- |
|
| 117 |
+ |
|
| 117 | 118 |
user.save() |
| 118 | 119 |
|
| 119 | 120 |
return response(200, 'Mini App Login Success', u'微信小程序登录成功', user.brand_qydata(brand_id=brand_id)) |
@@ -128,9 +129,9 @@ def query_userinfo(request): |
||
| 128 | 129 |
|
| 129 | 130 |
try: |
| 130 | 131 |
user = UserInfo.objects.get(memberusercardcode=memebercardcode, status=True) |
| 131 |
- except: |
|
| 132 |
+ except UserInfo.DoesNotExist: |
|
| 132 | 133 |
return response(UserStatusCode.USER_NOT_FOUND) |
| 133 |
- |
|
| 134 |
+ |
|
| 134 | 135 |
# 维修人工费 |
| 135 | 136 |
right = RightInfo.objects.get(right_id='X457xEV8KVxHQiTvhA7Dtf') |
| 136 | 137 |
coupons = UserCouponInfo.objects.filter(user_id=user.user_id, has_used=False, status=True) |
@@ -14,8 +14,8 @@ from pywe_storage import RedisStorage |
||
| 14 | 14 |
from TimeConvert import TimeConvert as tc |
| 15 | 15 |
|
| 16 | 16 |
from account.models import UserInfo |
| 17 |
-from statistic.models import RegisterStatisticInfo |
|
| 18 | 17 |
from mch.models import SaleclerkInfo |
| 18 |
+from statistic.models import RegisterStatisticInfo |
|
| 19 | 19 |
from utils.error.errno_utils import ProductBrandStatusCode, UserStatusCode |
| 20 | 20 |
from utils.redis.connect import r |
| 21 | 21 |
from utils.redis.rprofile import set_profile_info |
@@ -158,9 +158,10 @@ def mini_login_api(request): |
||
| 158 | 158 |
# 同步销售员手机号 |
| 159 | 159 |
try: |
| 160 | 160 |
saleclerk = SaleclerkInfo.objects.get(unionid=unionid, is_auth=True, status=True) |
| 161 |
+ except SaleclerkInfo.DoesNotExist: |
|
| 162 |
+ saleclerk = None |
|
| 163 |
+ if saleclerk: |
|
| 161 | 164 |
user.phone = saleclerk.clerk_phone |
| 162 |
- except: |
|
| 163 |
- pass |
|
| 164 | 165 |
user.unionid = unionid |
| 165 | 166 |
user.user_status = UserInfo.ACTIVATED |
| 166 | 167 |
user.signup_ip = client_ip(request) |
@@ -17,10 +17,11 @@ from account.models import UserInfo |
||
| 17 | 17 |
from coupon.models import UserCouponInfo |
| 18 | 18 |
from integral.models import SaleclerkIntegralIncomeExpensesInfo, SaleclerkSubmitLogInfo |
| 19 | 19 |
from logs.models import MchInfoEncryptLogInfo |
| 20 |
-from mch.models import BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, ModelInfo, SaleclerkInfo, MaintenancemanInfo |
|
| 20 |
+from mch.models import (BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, MaintenancemanInfo, ModelInfo, |
|
| 21 |
+ SaleclerkInfo) |
|
| 22 |
+from member.models import RightInfo |
|
| 21 | 23 |
from statistic.models import (DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, |
| 22 | 24 |
SaleclerkSaleStatisticInfo, SaleStatisticInfo) |
| 23 |
-from member.models import RightInfo |
|
| 24 | 25 |
from utils.error.errno_utils import (CouponStatusCode, ProductBrandStatusCode, ProductDistributorStatusCode, |
| 25 | 26 |
ProductMachineStatusCode, ProductModelStatusCode, SaleclerkStatusCode) |
| 26 | 27 |
|
@@ -454,19 +455,26 @@ def clerk_query_coupon(request): |
||
| 454 | 455 |
user_coupon = UserCouponInfo.objects.get(user_coupon_id=user_coupon_id) |
| 455 | 456 |
except UserCouponInfo.DoesNotExist: |
| 456 | 457 |
return response(CouponStatusCode.COUPON_NOT_FOUND) |
| 457 |
- |
|
| 458 |
+ |
|
| 458 | 459 |
right_detail = '' |
| 459 | 460 |
if is_maintenance: |
| 460 | 461 |
try: |
| 461 |
- maintenance = MaintenancemanInfo.objects.get(brand_id=brand.brand_id, user_id=user.user_id, status=True) |
|
| 462 |
- |
|
| 463 |
- # 维修人工费 |
|
| 462 |
+ maintenance = MaintenancemanInfo.objects.get(brand_id=brand.brand_id, user_id=user.user_id, status=True) |
|
| 463 |
+ except MaintenancemanInfo.DoesNotExist: |
|
| 464 |
+ return response(400001, 'MaintenancemanInfo Not Found', u'维修员不存在') |
|
| 465 |
+ |
|
| 466 |
+ # 维修人工费 |
|
| 467 |
+ try: |
|
| 464 | 468 |
right = RightInfo.objects.get(right_id='X457xEV8KVxHQiTvhA7Dtf') |
| 465 |
- member = UserInfo.objects.get(user_id=user_coupon.user_id) |
|
| 469 |
+ except RightInfo.DoesNotExist: |
|
| 470 |
+ return response(400001, 'MaintenancemanInfo Not Found', u'维修员不存在') |
|
| 466 | 471 |
|
| 467 |
- right_detail = right.maintaindata(level=member.level) |
|
| 468 |
- except: |
|
| 472 |
+ try: |
|
| 473 |
+ member = UserInfo.objects.get(user_id=user_coupon.user_id) |
|
| 474 |
+ except UserInfo.DoesNotExist: |
|
| 469 | 475 |
return response(400001, 'MaintenancemanInfo Not Found', u'维修员不存在') |
| 476 |
+ |
|
| 477 |
+ right_detail = right.maintaindata(level=member.level) |
|
| 470 | 478 |
else: |
| 471 | 479 |
try: |
| 472 | 480 |
clerk = SaleclerkInfo.objects.get(brand_id=brand.brand_id, clerk_phone=user.phone, status=True) |
@@ -503,40 +511,43 @@ def clerk_writeoff_coupon(request): |
||
| 503 | 511 |
brand = BrandInfo.objects.get(brand_id=brandID) |
| 504 | 512 |
except BrandInfo.DoesNotExist: |
| 505 | 513 |
return response(ProductBrandStatusCode.BRAND_NOT_FOUND) |
| 506 |
- |
|
| 514 |
+ |
|
| 507 | 515 |
try: |
| 508 | 516 |
user_coupon = UserCouponInfo.objects.get(user_coupon_id=user_coupon_id) |
| 509 |
- if user_coupon.has_used: |
|
| 510 |
- return response(CouponStatusCode.COUPON_HAS_USED) |
|
| 511 |
- elif user_coupon.is_coupon_admin_writeoff and not is_maintenance: |
|
| 512 |
- return response(CouponStatusCode.COUPON_PERMISSION_DENIED) |
|
| 513 |
- elif user_coupon.has_expired: |
|
| 514 |
- return response(CouponStatusCode.COUPON_EXPIRED) |
|
| 515 | 517 |
except UserCouponInfo.DoesNotExist: |
| 516 | 518 |
return response(CouponStatusCode.COUPON_NOT_FOUND) |
| 517 |
- |
|
| 519 |
+ |
|
| 520 |
+ if user_coupon.has_used: |
|
| 521 |
+ return response(CouponStatusCode.COUPON_HAS_USED) |
|
| 522 |
+ elif user_coupon.is_coupon_admin_writeoff and not is_maintenance: |
|
| 523 |
+ return response(CouponStatusCode.COUPON_PERMISSION_DENIED) |
|
| 524 |
+ elif user_coupon.has_expired: |
|
| 525 |
+ return response(CouponStatusCode.COUPON_EXPIRED) |
|
| 526 |
+ |
|
| 518 | 527 |
user_coupon.has_used = True |
| 519 | 528 |
user_coupon.used_at = tc.utc_datetime() |
| 520 | 529 |
|
| 521 | 530 |
if is_maintenance: |
| 522 | 531 |
try: |
| 523 |
- maintenance = MaintenancemanInfo.objects.get(brand_id=brand.brand_id, user_id=user.user_id, status=True) |
|
| 524 |
- user_coupon.admin_id = maintenance.maintenance_id |
|
| 525 |
- user_coupon.admin_name = maintenance.maintenance_name |
|
| 526 |
- user_coupon.save() |
|
| 527 |
- except: |
|
| 532 |
+ maintenance = MaintenancemanInfo.objects.get(brand_id=brand.brand_id, user_id=user.user_id, status=True) |
|
| 533 |
+ except MaintenancemanInfo.DoesNotExist: |
|
| 528 | 534 |
return response(400001, 'MaintenancemanInfo Not Found', u'维修员不存在') |
| 535 |
+ |
|
| 536 |
+ user_coupon.admin_id = maintenance.maintenance_id |
|
| 537 |
+ user_coupon.admin_name = maintenance.maintenance_name |
|
| 538 |
+ user_coupon.save() |
|
| 529 | 539 |
else: |
| 530 | 540 |
try: |
| 531 | 541 |
clerk = SaleclerkInfo.objects.get(brand_id=brand.brand_id, clerk_phone=user.phone, status=True) |
| 532 |
- user_coupon.clerk_id = clerk.clerk_id |
|
| 533 |
- user_coupon.clerk_name = clerk.clerk_name |
|
| 534 |
- user_coupon.distributor_id = clerk.distributor_id |
|
| 535 |
- user_coupon.distributor_name = clerk.distributor_name |
|
| 536 |
- user_coupon.save() |
|
| 537 | 542 |
except SaleclerkInfo.DoesNotExist: |
| 538 | 543 |
return response(SaleclerkStatusCode.CLERK_NOT_FOUND) |
| 539 | 544 |
|
| 545 |
+ user_coupon.clerk_id = clerk.clerk_id |
|
| 546 |
+ user_coupon.clerk_name = clerk.clerk_name |
|
| 547 |
+ user_coupon.distributor_id = clerk.distributor_id |
|
| 548 |
+ user_coupon.distributor_name = clerk.distributor_name |
|
| 549 |
+ user_coupon.save() |
|
| 550 |
+ |
|
| 540 | 551 |
return response(200, 'Write Off Coupon Success', u'劵核销成功') |
| 541 | 552 |
|
| 542 | 553 |
|
@@ -3,8 +3,8 @@ |
||
| 3 | 3 |
from django.conf import settings |
| 4 | 4 |
from django_redis_connector import connector |
| 5 | 5 |
from pywe_storage import RedisStorage |
| 6 |
- |
|
| 7 | 6 |
from pywe_user import get_all_users |
| 7 |
+ |
|
| 8 | 8 |
from utils.redis.rkeys import SUBSCRIBE_USERINFO_LIST |
| 9 | 9 |
|
| 10 | 10 |
|